﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace Gmantis.Controls.DataGrid
{
    public class DataGridBoundConverter : IValueConverter
    {
        public virtual object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (targetType == typeof(string))
            {
                string format = "{0}";
                string str2 = parameter as string;
                if (!string.IsNullOrEmpty(str2))
                {
                    format = "{0:" + str2 + "}";
                }
                try
                {
                    return string.Format(culture, format, new object[] { value });
                }
                catch (NotSupportedException)
                {
                    return string.Format("{0}", value);
                }
                catch (FormatException)
                {
                    return string.Format(culture, "{0}", new object[] { value });
                }
            }
            return value;
        }

        public virtual object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value;
        }
    }
}
